package com.gexin.model.activity;

import com.gexin.model.activity.base.BaseMemberInfo;
import com.gexin.model.enums.MemberInfoEnum;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 业务名称:  t_member_info()
 */
@SuppressWarnings("serial")
public class MemberInfo extends BaseMemberInfo<MemberInfo> {
	public static final MemberInfo dao = new MemberInfo();



	public void setMemberInfo(String id, String userId, Integer level, String phone){

		this.setId(id);
		this.setUserId(userId);
	/*	if(level==1){
			this.(integral);
		}else{
			this.setS(integral);tring
		}*/
	
		this.setLevel(level);
//		this.setPhone(phone);
		Date date = new Date();
		this.setCreateTime(date.getTime());
		this.setUpdateTime(date.getTime());

	}

	public MemberInfo getMemberInfoByUserId(String id){
		MemberInfo memberInfo = MemberInfo.dao.findFirst("select * from t_member_info where user_id=" + id );
		return memberInfo;
	}
	public List<MemberInfo> getMemberInfoByUser(){
		List<MemberInfo> memberInfoList = MemberInfo.dao.find("SELECT a.*,b.level,b.create_time,t.speed_integral,t.forecast_speed_integral,t.coin,t.bill_coupon FROM t_weixin_user as a LEFT JOIN t_member_info b on a.id=b.user_id LEFT JOIN t_member_bill_speed_integral AS t on a.id=t.user_id");
		return memberInfoList;
	}

	public MemberInfo getMemberFankeInfoByUserId(String id){
		MemberInfo memberInfo = MemberInfo.dao.findFirst("select * from t_member_info where user_id=" + id + " and " +
				"level="+ MemberInfoEnum.THIRD_LEVEL.getCode() +" or level="+ MemberInfoEnum.SECOND_LEVEL.getCode()+
				" and user_id="+id);
		return memberInfo;
	}
	public void test(Integer price,int type){
		Integer integral = 0;
//		if(MemberInfoEnum.FIRST_LEVEL.getCode()==this.getLevel()){
//			 integral = this.getNormalIntegral();
//		}else{
//			 integral = this.getFansIntegral();
//		}
		if(integral == null||integral == 0) return;
		if(integral<price)return;
		integral -= price;
// 		if(MemberInfoEnum.FIRST_LEVEL.getCode()==this.getLevel()){
//			 this.setNormalIntegral(integral);
//		}else{
//			 this.setFansIntegral(integral);
//		}
	}

//  获取到所有会员(粉客,推广者)
	public List<MemberInfo>  memberFankeInfoList(int second,int third){
		List<MemberInfo> memberFankeInfoList = MemberInfo.dao.find("select * from t_member_info where level= 2 or level=3");
		return memberFankeInfoList;
	}

}
